package interfaces;

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.IntConsumer;
import java.util.stream.Stream;

import interfaces.Employee;
import interfaces.LengthComparator;

public class Main {

    public static void main(String[] args) {
        System.out.println("lalala");

        Employee boss = new Employee("boss", 1000);
        Employee peter  = new Employee("peter", 100);

        Employee[] array = {boss, peter};
        Arrays.sort(array);
        System.out.println(array[0].getName());
        System.out.println(array[1].getName());

        String[] friends = { "Peter", "Pau", "Mary" };
        // Arrays.sort(friends, new LengthComparator());
        // Arrays.sort(friends, (first, second) -> first.length() - second.length());
        Arrays.sort(friends, String::compareToIgnoreCase);
        // Arrays.sort(friends, Application.compareInDirecton(1));
        // System.out.println(Arrays.toString(friends));
        // Arrays.sort(friends, Application.compareInDirecton(-1));
        System.out.println(Arrays.toString(friends));

        Arrays.sort(friends, Application.reverse(String::compareToIgnoreCase));
        System.out.println(Arrays.toString(friends));


        System.out.println("=======================================================");


        // List<String> names = new ArrayList<>(Arrays.asList(friends));
        // Stream<Employee> stream = names.stream().map(Employee::new);
        // Employee[] buttons = stream.toArray(Employee[]::new);
        // for (Employee em : buttons) {
        //     System.out.println(em.getName());
        // }

        // repeat(10, i -> System.out.println("Countdown:"+(9-i)));

        // System.out.println("=======================================================");

        // Application.repeatMessage(" Application.repeatMessage", 3);

        // for (int i = 0; i < 5; i++) {
        //     new Thread(() -> System.out.println(i)).start();
        //     // Error—cannot capture i
        // }

        // System.out.println("=======================================================");


    }

    public static void repeat(int n, IntConsumer action) {
        for (int i = 0; i < n; i++) {
            action.accept(i);;
        }
    }

    BufferedImage createImage(int width, int height, PixelFunction f) {
        BufferedImage image = new BufferedImage(width, height,
        BufferedImage.TYPE_INT_RGB);
        for (int x = 0; x < width; x++)
        for (int y = 0; y < height; y++) {
            Color color = f.apply(x, y);
            image.setRGB(x, y, color.getRGB());
        }
        return image;
    }
}